// custom-tab-bar/index.js
import {
  storeBindingsBehavior
} from 'mobx-miniprogram-bindings'
import {
  store
} from '../store/index'
Component({
  options: {
    styleIsolation: 'shared',
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      sum: 'sum',
      active: 'activeTabIndex'
    },
    actions: {
      changeIndex:'changeIndex'
    }
  },
  observers: {
    'sum': function (val) {
      this.setData({
        'list[1].info': val
      })
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {

    "list": [{
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/icon/index.png",
        "selectedIconPath": "/icon/search.png"
      },
      {
        "pagePath": "/pages/logs/logs",
        "text": "我的",
        "iconPath": "/icon/my.png",
        "selectedIconPath": "/icon/img.png",
        info: 5
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.setData({
        active: event.detail
      });
      this.changeIndex(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
      console.log(event.detail);
    },
  }
})